{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7ba6ce81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "# 我的第一个神经网络\n",
    "# 至少3个函数：1.初始化函数，设定输入层节点，隐藏层和输出层\n",
    "# 2，训练， 给定训练集样本后，优化权重\n",
    "# 3，查询 给定输入，从输出节点获取结果。\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8eaf004",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 编写一个神经网络框架\n",
    "class neuralNetwork:\n",
    "    def __init__() :\n",
    "# 设置输入输入层，隐藏层，输出层节点的梳理，这些节点定义了神经网络的形状和尺寸。\n",
    "        pass\n",
    "    def train() : \n",
    "        pass\n",
    "    def query() :\n",
    "        pass\n",
    "    pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a642d719",
   "metadata": {},
   "outputs": [],
   "source": [
    "class neuralNetwork_one:\n",
    "    def __init__ (self,inputnodes,hiddennodes,outputnodes,learningrate):\n",
    "        self.inodes = inputnodes;\n",
    "        self.hnodes = hiddennodes;\n",
    "        self.onodes = outputnodes;\n",
    "        \n",
    "        # learning rate \n",
    "        self.lr=learningrate\n",
    "        pass\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e698956",
   "metadata": {},
   "outputs": [],
   "source": [
    "#  尝试创建每层3个节点，学习率为0.5 的小型神经网络\n",
    "input_nodes =3 \n",
    "hidden_nodes = 3\n",
    "output_nodes = 3\n",
    "# learning rate is 0.3 \n",
    "learning_rate = 0.3\n",
    "\n",
    "# create instance \n",
    "n = neuralNetwork_one(input_nodes,hidden_nodes,output_nodes,learning_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96cf6a68",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建权重矩阵\n",
    "import numpy\n",
    "numpy.random.rand(3,3) -0.5\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efe24429",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建两个链接权重矩阵\n",
    "self.wih =(numpy.random.rand(self.hnodes,self.inodes)-0.5)\n",
    "self.who =(numpy.random.rand(self.onodes,self.hnodes)-0.5)\n",
    "# 创建较复杂的权重\n",
    "# 使用正态分布采样权重，平均值为0，标准方差为节点传入链接数目的开方。\n",
    "self.wih =numpy.random.normal(0.0,pow(self.hnodes,-0.5),(self.hnodes,self.inodes))\n",
    "self.who =numpy.random.normal(0.0,pow(self.onodes,-0.5),(self.onodes,self.hnodes))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2aa86d9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询网络  \n",
    "# 使用numpy进行点乘运算\n",
    "hidden_inputs = numpy.dot(self.wih,inputs)\n",
    "# 定义激活函数 Sigmoid(x) \n",
    "import scipy.special\n",
    "# 使用激活函数 应用于进入隐藏节点的信号，即节点激活\n",
    "self.actication_function = lambda x : scipy.special.expit(x)\n",
    "# 应用激活函数\n",
    "hiden_oputputs =self.activation_function(hidden_inputs)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49b740b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义隐藏输出层 代码\n",
    "final_inputs = numpy.dot(self.who,hidden_outputs)\n",
    "final_outpus = self.activation_function(final_inputs)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0028a5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 迄今的网络\n",
    "import numpy\n",
    "import scipy.special\n",
    "class neuralNetwork_one:\n",
    "    def __init__ (self,inputnodes,hiddennodes,outputnodes,learningrate):\n",
    "        self.inodes = inputnodes;\n",
    "        self.hnodes = hiddennodes;\n",
    "        self.onodes = outputnodes;\n",
    "        # 定义权重矩阵\n",
    "        self.wih =(numpy.random.rand(self.hnodes,self.inodes)-0.5)\n",
    "        self.who =(numpy.random.rand(self.onodes,self.hnodes)-0.5)\n",
    "        # learning rate \n",
    "        self.lr=learningrate\n",
    "        # 定义激活函数\n",
    "        self.actication_function = lambda x : scipy.special.expit(x)\n",
    "        pass\n",
    "    def train() :\n",
    "        pass\n",
    "    def query(self,inputs_list) :\n",
    "        inputs = numpy.array(inputs_list,ndmin=2)\n",
    "        hidden_inputs = numpy.dot(self.wih,inputs)\n",
    "        hiden_oputputs =self.activation_function(hidden_inputs)\n",
    "        final_inputs = numpy.dot(self.who,hidden_outputs)\n",
    "        final_outpus = self.activation_function(final_inputs)  \n",
    "        return final_outpus\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "304a2bfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练函数\n",
    "def train(self,inputs_list,targets_list):\n",
    "# 第一部分，因为要获取对应的输出值，所以这部分与query()并没有很大的差距    \n",
    "    # 转换输入为线性列表\n",
    "    input=numpy.array(inputs_list,ndmin=2).T\n",
    "    targets=numpy.array(targets_list,ndmin=2).T\n",
    "    # 计算 隐藏层的输入与输出\n",
    "    hidden_inputs=numpy.dot(self.wih,inputs)\n",
    "    hidden_outputs=self.activation_function(hidden_inputs)\n",
    "    # 计算 输出层\n",
    "    final_inputs=numpy.dot(self.who,hidden_outputs)\n",
    "    final_outputs=self.activation_function(final_inputs)\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "173f8bda",
   "metadata": {},
   "outputs": [],
   "source": [
    "# create instance of one \n",
    "input_nodes = 3\n",
    "hidden_nodes = 3\n",
    "output_nodes = 3\n",
    "learning_rate = 0.5\n",
    "n=neuralNetwork_one(input_nodes,hidden_nodes,output_nodes,learning_rate)\n",
    "print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "778b29ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完整的神经网络\n",
    "import numpy\n",
    "import scipy.special\n",
    "class neuralNetwork_one:\n",
    "    def __init__ (self,inputnodes,hiddennodes,outputnodes,learningrate):\n",
    "        self.inodes = inputnodes;\n",
    "        self.hnodes = hiddennodes;\n",
    "        self.onodes = outputnodes;\n",
    "        # 定义权重矩阵\n",
    "      # self.wih =(numpy.random.rand(self.hnodes,self.inodes)-0.5)\n",
    "      #  self.who =(numpy.random.rand(self.onodes,self.hnodes)-0.5)\n",
    "        self.wih =numpy.random.normal(0.0,pow(self.inodes,-0.5),(self.hnodes,self.inodes))\n",
    "        self.who =numpy.random.normal(0.0,pow(self.hnodes,-0.5),(self.onodes,self.hnodes))\n",
    "        # learning rate \n",
    "        self.lr=learningrate\n",
    "        # 定义激活函数\n",
    "        self.activation_function = lambda x : scipy.special.expit(x)\n",
    "        pass\n",
    "    # 训练函数\n",
    "    def train(self,inputs_list,targets_list):\n",
    "    # 第一部分，因为要获取对应的输出值，所以这部分与query()并没有很大的差距    \n",
    "        # 转换输入为线性列表\n",
    "        inputs=numpy.array(inputs_list,ndmin=2).T\n",
    "        targets=numpy.array(targets_list,ndmin=2).T\n",
    "        # 计算 隐藏层的输入与输出\n",
    "        hidden_inputs=numpy.dot(self.wih,inputs)\n",
    "        hidden_outputs=self.activation_function(hidden_inputs)\n",
    "        \n",
    "        # 计算 输出层\n",
    "        final_inputs=numpy.dot(self.who,hidden_outputs)\n",
    "        final_outputs=self.activation_function(final_inputs)\n",
    "        # 计算误差\n",
    "        output_errors= targets-final_outputs\n",
    "        # 隐藏层的误差是隐藏层到输出层的权重的转置矩阵与输出层的误差的点乘\n",
    "        hidden_errors=numpy.dot(self.who.T,output_errors)\n",
    "        # 权重的更新 更新隐藏层到输出层\n",
    "        self.who += self.lr*numpy.dot((output_errors*final_outputs *(1.0-final_outputs)),numpy.transpose(hidden_outputs)) \n",
    "        # 更新输入层到隐藏层权重\n",
    "        self.wih += self.lr*numpy.dot((hidden_errors*hidden_outputs*(1.0-hidden_outputs)),numpy.transpose(inputs))\n",
    "        pass\n",
    "    def query(self,inputs_list) :\n",
    "        inputs = numpy.array(inputs_list,ndmin=2).T\n",
    "        hidden_inputs = numpy.dot(self.wih,inputs)\n",
    "        hiden_oputputs =self.activation_function(hidden_inputs)\n",
    "        \n",
    "        final_inputs = numpy.dot(self.who,hiden_oputputs)\n",
    "        final_outpus = self.activation_function(final_inputs)  \n",
    "        return final_outpus\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e993580f",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_file =open(r\"C:\\Users\\wangm\\Desktop\\PythonData\\mnist_train.csv\",\"r\")\n",
    "data_list = data_file.readlines()\n",
    "\n",
    "data_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f30af2c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "60000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,159,253,159,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,238,252,252,252,237,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54,227,253,252,239,233,252,57,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,60,224,252,253,252,202,84,252,253,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,163,252,252,252,253,252,252,96,189,253,167,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,238,253,253,190,114,253,228,47,79,255,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,238,252,252,179,12,75,121,21,0,0,253,243,50,0,0,0,0,0,0,0,0,0,0,0,0,0,38,165,253,233,208,84,0,0,0,0,0,0,253,252,165,0,0,0,0,0,0,0,0,0,0,0,0,7,178,252,240,71,19,28,0,0,0,0,0,0,253,252,195,0,0,0,0,0,0,0,0,0,0,0,0,57,252,252,63,0,0,0,0,0,0,0,0,0,253,252,195,0,0,0,0,0,0,0,0,0,0,0,0,198,253,190,0,0,0,0,0,0,0,0,0,0,255,253,196,0,0,0,0,0,0,0,0,0,0,0,76,246,252,112,0,0,0,0,0,0,0,0,0,0,253,252,148,0,0,0,0,0,0,0,0,0,0,0,85,252,230,25,0,0,0,0,0,0,0,0,7,135,253,186,12,0,0,0,0,0,0,0,0,0,0,0,85,252,223,0,0,0,0,0,0,0,0,7,131,252,225,71,0,0,0,0,0,0,0,0,0,0,0,0,85,252,145,0,0,0,0,0,0,0,48,165,252,173,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,253,225,0,0,0,0,0,0,114,238,253,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,252,249,146,48,29,85,178,225,253,223,167,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,252,252,252,229,215,252,252,252,196,130,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,199,252,252,253,252,252,233,145,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,128,252,253,252,141,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\\n'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(len(data_list))\n",
    "data_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0172735b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2098cf83390>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAZtUlEQVR4nO3df2jU9x3H8ddp9WblcjSzyV1mDKEoW41Tqs4o/oiCwYzJbFawFbbIQNoZAyEWmZNhNrakOBT/yGqxDKesrv5jraBUUzRxnTpSSVFcEMU4MzTLDPYupvbE5rM/gsfOxB/f8y7vXPJ8wIH53n28d7/9mqdf7+4bn3POCQAAA2OsBwAAjF5ECABghggBAMwQIQCAGSIEADBDhAAAZogQAMAMEQIAmHnOeoCH9fX16caNGwoEAvL5fNbjAAA8cs6pp6dHeXl5GjPm8ec6wy5CN27cUH5+vvUYAIBn1NHRocmTJz/2McMuQoFAQFL/8FlZWcbTAAC8ikajys/Pj38/f5y0Rejdd9/VH/7wB928eVPTp0/Xzp07tWjRoieue/BPcFlZWUQIADLY07ykkpY3Jhw4cEDV1dXasmWLWltbtWjRIpWVlen69evpeDoAQIbypeMq2vPmzdMrr7yiXbt2xbd973vf06pVq1RfX//YtdFoVMFgUJFIhDMhAMhAXr6Pp/xM6N69ezp37pxKS0sTtpeWlur06dMDHh+LxRSNRhNuAIDRIeURunXrlr755hvl5uYmbM/NzVVnZ+eAx9fX1ysYDMZvvDMOAEaPtH1Y9eEXpJxzg75It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U/+tGPXCAQGPH7oKenx7W2trrW1lYnye3YscO1tra6f/3rX84559555x0XDAbdwYMH3YULF9wbb7zhwuGwi0ajxpOn1uP2Q09Pj9u4caM7ffq0a29vdydPnnTz58933/nOd0bUfvjFL37hgsGga2pqcjdv3ozfvvrqq/hjRsPx8KT9kEnHQ8ZEyDnn/vjHP7qCggI3fvx498orryS8HXE0WL16tQuHw27cuHEuLy/PlZeXu4sXL1qPlXYnT550kgbcKioqnHP9b8vdunWrC4VCzu/3u8WLF7sLFy7YDp0Gj9sPX331lSstLXUvvviiGzdunJsyZYqrqKhw169ftx47pQb775fk9uzZE3/MaDgenrQfMul44Ec5AADMZMRrQgCAkYkIAQDMECEAgBkiBAAwQ4QAAGaIEADADBECAJghQgAAM0QIAGCGCAEAzBAhAIAZIgQAMPM/ocjwWJnwpcEAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 将像素进行点阵绘制\n",
    "import numpy\n",
    "import matplotlib.pyplot\n",
    "all_values =data_list[123].split(',')\n",
    "image_array=numpy.asfarray(all_values[1:]).reshape((28,28))\n",
    "matplotlib.pyplot.imshow(image_array,cmap=\"Greys\",interpolation='none')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1066c9b7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 创建一个用于训练的神经网络\n",
    "input_nodes =784\n",
    "hideen_nodes =100\n",
    "output_nodes =10 \n",
    "# 学习率\n",
    "learning_rate = 0.3\n",
    "\n",
    "# 创建实例\n",
    "n = neuralNetwork_one(input_nodes,hideen_nodes,output_nodes,learning_rate)\n",
    "\n",
    "traning_data_file=open(r\"C:\\Users\\wangm\\Desktop\\PythonData\\mnist_train.csv\",\"r\")\n",
    "traning_data_list=traning_data_file.readlines()\n",
    "traning_data_file.close()\n",
    "# 开始训练\n",
    "# 设置训练次数\n",
    "epochs = 200\n",
    "for e in range(epochs):\n",
    "    for record in traning_data_list :\n",
    "        all_values=record.split(',')\n",
    "        inputs=(numpy.asfarray(all_values[1:])/255.0 * 0.99)+0.01\n",
    "        targets=numpy.zeros(output_nodes) + 0.01\n",
    "        targets[int(all_values[0])] =0.99\n",
    "        n.train(inputs,targets)\n",
    "        pass\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "075a6185",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "label: 7\n",
      "2\n",
      "label: 2\n",
      "1\n",
      "label: 1\n",
      "0\n",
      "label: 0\n",
      "4\n",
      "label: 4\n",
      "1\n",
      "label: 1\n",
      "4\n",
      "label: 3\n",
      "9\n",
      "label: 9\n",
      "5\n",
      "label: 6\n",
      "9\n",
      "label: 9\n",
      "0\n",
      "label: 0\n",
      "6\n",
      "label: 6\n",
      "9\n",
      "label: 9\n",
      "0\n",
      "label: 0\n",
      "1\n",
      "label: 1\n",
      "5\n",
      "label: 5\n",
      "9\n",
      "label: 9\n",
      "7\n",
      "label: 7\n",
      "3\n",
      "label: 8\n",
      "4\n",
      "label: 4\n",
      "9\n",
      "label: 9\n",
      "6\n",
      "label: 6\n",
      "6\n",
      "label: 6\n",
      "5\n",
      "label: 5\n",
      "4\n",
      "label: 4\n",
      "0\n",
      "label: 0\n",
      "7\n",
      "label: 7\n",
      "4\n",
      "label: 4\n",
      "0\n",
      "label: 0\n",
      "1\n",
      "label: 1\n",
      "3\n",
      "label: 3\n",
      "1\n",
      "label: 1\n",
      "3\n",
      "label: 3\n",
      "4\n",
      "label: 6\n",
      "7\n",
      "label: 7\n",
      "2\n",
      "label: 2\n",
      "7\n",
      "label: 7\n",
      "1\n",
      "label: 1\n",
      "2\n",
      "label: 2\n",
      "1\n",
      "label: 1\n",
      "1\n",
      "label: 1\n",
      "7\n",
      "label: 7\n",
      "4\n",
      "label: 4\n",
      "2\n",
      "label: 2\n",
      "3\n",
      "label: 3\n",
      "5\n",
      "label: 5\n",
      "1\n",
      "label: 1\n",
      "2\n",
      "label: 2\n",
      "4\n",
      "label: 4\n",
      "4\n",
      "label: 4\n",
      "[1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAZpUlEQVR4nO3dfWiV9/3/8dfR6qm6kwNBk3POTLMwtBsqbt4sGupdmaEpStN0YG8YykDaNTokLWWZDLMNTHGtOMh0tKxWWa3+492m1GZoYjvrUJeuznUSMc4McxYM9pyYuhOsn98f4vl9j4k31/GcvHOS5wMuMOect+fj5UWeXp5zrvicc04AABgYYb0AAMDwRYQAAGaIEADADBECAJghQgAAM0QIAGCGCAEAzBAhAICZh6wXcLsbN27o0qVLCgQC8vl81ssBAHjknFN3d7cikYhGjLj7uc6gi9ClS5dUVFRkvQwAwANqb2/XxIkT7/qYQRehQCAg6ebi8/LyjFcDAPAqHo+rqKgo+f38brIWoc2bN+vXv/61Ojo6NGXKFG3atEnz5s2759yt/4LLy8sjQgCQw+7nJZWsvDFh165dWrNmjdauXauWlhbNmzdPFRUVunjxYjaeDgCQo3zZuIp2aWmpZsyYoS1btiRv+/a3v63KykrV19ffdTYejysYDCoWi3EmBAA5yMv38YyfCfX29urUqVMqLy9Pub28vFzHjh3r8/hEIqF4PJ6yAQCGh4xH6PLly/rqq69UWFiYcnthYaGi0Wifx9fX1ysYDCY33hkHAMN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edef/11FwwG3e7du93p06fdc88958LhsIvH48Yrz6y77Yfu7m73yiuvuGPHjrm2tjZ35MgRN3fuXPf1r399SO2HH//4xy4YDLqmpibX0dGR3L788svkY4bD8XCv/ZBLx0PORMg5537729+64uJiN3r0aDdjxoyUtyMOB8uWLXPhcNiNGjXKRSIRV1VV5c6cOWO9rKw7cuSIk9RnW758uXPu5tty161b50KhkPP7/W7+/Pnu9OnTtovOgrvthy+//NKVl5e7CRMmuFGjRrlHHnnELV++3F28eNF62RnV359fktu6dWvyMcPheLjXfsil44Ef5QAAMJMTrwkBAIYmIgQAMEOEAABmiBAAwAwRAgCYIUIAADNECABghggBAMwQIQCAGSIEADBDhAAAZogQAMDM/wMFhPfUIu8uLAAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试网络\n",
    "test_data_file= open(r\"C:\\Users\\wangm\\Desktop\\PythonData\\mnist_test.csv\",\"r\")\n",
    "test_data_list=test_data_file.readlines()\n",
    "test_data_file.close()\n",
    "# 设置计分卡，1 为正确，0为错误。\n",
    "scorecard = []\n",
    "for x in range(50):\n",
    "    all_values =test_data_list[x].split(',')\n",
    "    correct_label =int(all_values[0])\n",
    "    print(all_values[0])\n",
    "    image_array =numpy.asfarray(all_values[1:]).reshape((28,28))\n",
    "    matplotlib.pyplot.imshow(image_array,cmap=\"Greys\",interpolation='None')\n",
    "    outputs = n.query((numpy.asfarray(all_values[1:]) / 255.0 * 0.99)+ 0.01)\n",
    "    # print(outputs)\n",
    "    label = numpy.argmax(outputs)\n",
    "    print('label:',label)\n",
    "    if (label == correct_label):\n",
    "        scorecard.append(1)\n",
    "    else:\n",
    "        scorecard.append(0)\n",
    "        pass\n",
    "   \n",
    "    pass \n",
    "print(scorecard)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e139dce",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "138944b0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
